home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / bnklysrc / xfermdm7.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-05  |  7.5 KB  |  174 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello  */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                        MODEM7 file name transfer                         */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.210.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU SHOULD  IMMEDIATELY CONTACT THE AUTHORS    */
  24. /*    AT THE  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO    */
  25. /*    USE   THIS  FILE  WITHOUT  HAVING   ACCEPTED  THE  TERMS  OF   THE    */
  26. /*    BINKLEYTERM  LICENSING AGREEMENT,  OR SUCH OTHER  AGREEMENT AS YOU    */
  27. /*    ARE ABLE TO REACH WITH THE AUTHORS.                                   */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /*    The Authors can be reached at the following addresses:                */
  31. /*                                                                          */
  32. /*    Robert C. Hartman                      Vincent E. Perriello           */
  33. /*    Spark Software                         VEP Software                   */
  34. /*    427-3 Amherst Street                   111 Carroll Street             */
  35. /*    CS2032, Suite 232                      Naugatuck, CT 06770            */
  36. /*    Nashua, NH 03061                                                      */
  37. /*                                                                          */
  38. /*    FidoNet 1:132/101                      FidoNet 1:141/491              */
  39. /*    Data    (603) 888-8179                 Data    (203) 729-7569         */
  40. /*                                                                          */
  41. /*    Please feel free to contact us at any time to share your comments     */
  42. /*    about our software and/or licensing policies.                         */
  43. /*                                                                          */
  44. /*                                                                          */
  45. /*  This module is based largely on a similar module in OPUS-CBCS V1.03b.   */
  46. /*  The original work is (C) Copyright 1987, Wynn Wagner III. The original  */
  47. /*  author has graciously allowed us to use his code in this work.          */
  48. /*                                                                          */
  49. /*--------------------------------------------------------------------------*/
  50.  
  51. #include <ctype.h>
  52. #include <conio.h>
  53.  
  54. #ifdef __TURBOC__
  55. #include <mem.h>
  56. #else
  57. #include <memory.h>
  58. #endif
  59.  
  60. #include "com.h"
  61. #include "xfer.h"
  62. #include "zmodem.h"
  63. #include "keybd.h"
  64. #include "sbuf.h"
  65. #include "sched.h"
  66. #include "externs.h"
  67. #include "prototyp.h"
  68. #include "find.h"                   /*PLF Fri  05-05-1989  23:03:42 */
  69.  
  70.  
  71. /*--------------------------------------------------------------------------*/
  72. /* XFERMDM7                                                                 */
  73. /*--------------------------------------------------------------------------*/
  74. int xfermdm7 (fn)
  75. char *fn;
  76. {
  77.    unsigned char checksum;
  78.    int i, j;
  79.    unsigned char mdm7_head[13];
  80.    unsigned char num_tries = '\0';
  81.    char *fname;
  82.    FSCAN *dhand;                    /*PLF Fri  05-05-1989  22:56:40 */
  83.  
  84.    XON_DISABLE ();
  85.    dhand = opendir();               /*PLF Fri  05-05-1989  23:02:49 */
  86.    findfirst(fn, _A_NORMAL, dhand); /*PLF Fri  05-05-1989  23:02:50 */
  87.    fname = dhand->name;             /*PLF Fri  05-05-1989  23:02:52 */
  88.  
  89.    /*--------------------------------------------------------------------*/
  90.    /* Build a Modem7 style head                                          */
  91.    /*--------------------------------------------------------------------*/
  92.    memset (mdm7_head, ' ', 12);
  93.    for (i = j = 0; ((fname[i]) && (i < 12) && (j < 12)); i++)
  94.       {
  95.       if (fname[i] == '.')
  96.          j = 8;
  97.       else mdm7_head[j++] = (char) toupper (fname[i]);
  98.       }
  99.    closedir(dhand);                 /*PLF Fri  05-05-1989  23:02:42 */
  100.    checksum = SUB;
  101.    for (i = 0; i < 11; i++)
  102.       checksum += mdm7_head[i];
  103.  
  104.    /*--------------------------------------------------------------------*/
  105.    /* Top of the Name-Transfer Loop                                      */
  106.    /*--------------------------------------------------------------------*/
  107. top:
  108.    if (!CARRIER)
  109.       return 0;
  110.    else if (num_tries++ > 10)
  111.       {
  112.       message (_s_mdm7giveup);
  113.       send_can ();
  114.       return (0);
  115.       }
  116.    else if (num_tries)
  117.       SENDBYTE ('u');
  118.  
  119.    /*--------------------------------------------------------------------*/
  120.    /* Wait for a Nak                                                     */
  121.    /*--------------------------------------------------------------------*/
  122.    for (i = 0; i < 15; i++)
  123.       {
  124.       if (!CARRIER)
  125.          return (0);
  126.       j = TIMED_READ (4);
  127.       switch (j)
  128.          {
  129.          case 'C':
  130.             SENDBYTE (SOH);
  131.             return 2;
  132.          case NAK:
  133.             i = 16;
  134.             break;
  135.          case CAN:
  136.             return 0;
  137.          }
  138.       }
  139.  
  140.    /*--------------------------------------------------------------------*/
  141.    /* Transmit the file name                                             */
  142.    /*--------------------------------------------------------------------*/
  143.    SENDBYTE (ACK);
  144.    for (i = 0; i < 11; i++)
  145.       {
  146.       SENDBYTE (mdm7_head[i]);
  147.       switch (j = TIMED_READ (10))
  148.          {
  149.          case ACK:
  150.             break;
  151.          case CAN:
  152.             SENDBYTE (ACK);
  153.             return (0);
  154.          default:                               /* cprintf(_s_mdm7idunno,j); */
  155.             goto top;
  156.          }                                       /* switch */
  157.       }
  158.  
  159.    /*--------------------------------------------------------------------*/
  160.    /* Transmit SUB and get CheckSum                                      */
  161.    /*--------------------------------------------------------------------*/
  162.    SENDBYTE (SUB);
  163.    if ((i = TIMED_READ (10)) != checksum)
  164.       {
  165.       message (_s_mdm7chksum);
  166.       goto top;
  167.       }
  168.  
  169.    SENDBYTE (ACK);
  170.    return (1);
  171. }
  172.  
  173. /* END OF FILE: xfermdm7.c */
  174.